package top.onedream.buildsmallsoftware.cfg

import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.stereotype.Component
import org.yeauty.standard.ServerEndpointExporter
import top.onedream.buildsmallsoftware.component.messages.NioWebSocket
import top.onedream.buildsmallsoftware.util.RedisCache


@Component
class WebSocketConfig {
    /**
     * 秘密
     * */
    @Value("\${jwt.secret}")
    private val secret: String? = null

    /**
     * 服务器端点出口国
     * @return [ServerEndpointExporter?]
     */
    @Bean
    fun serverEndpointExporter(): ServerEndpointExporter? {
        return ServerEndpointExporter()
    }

    /**
     * 设置消息服务
     * @param [redisCache] 复述,缓存
     * @param [objectMapper] 对象映射器
     */
    @Autowired
    fun setMessageService(
        redisCache: RedisCache,
        objectMapper: ObjectMapper
    ) {
        NioWebSocket.socketUtil.redisCache = redisCache
        NioWebSocket.socketUtil.secret = secret
        NioWebSocket.socketUtil.objectMapper = objectMapper
    }
}